<?php
namespace Modules\Cli;

use Phalcon\DiInterface;

class Module implements \Phalcon\Mvc\ModuleDefinitionInterface {
    /**
     * Registers an autoloader related to the module
     *
     * @param DiInterface $di
     */
    public function registerAutoloaders(DiInterface $di = null) {
        (new \Phalcon\Loader())->registerNamespaces([
          'Common' => BASE_PATH . '/src/common',

            __NAMESPACE__ . '\\Tasks' => __DIR__ . '/tasks/',
        ]) -> register();
    }

    /**
     * Registers services related to the module
     *
     * @param DiInterface $di
     */
    public function registerServices(DiInterface $di) {
      $di -> set('backendCache', function() {
      $filename = BASE_PATH . 'runtime/cache/';
      if(!is_dir($filename)) {
        mkdir($filename, 0777, true);
      }

      return new \Phalcon\Cache\Backend\File(
        \Phalcon\Cache\Frontend\Factory::load([
          'adapter' => 'data'
        ]),
        [
          'cacheDir' => $filename
        ]
      );
    });
    }
}
